package cn.itcast.hotel.service.rabbitmqlistener;

import cn.itcast.hotel.service.rabbitmqlistener.mqconstants.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ClassName:HotelMqExchange
 * Package:cn.itcast.hotel.rabbitmqlistener
 * Description:
 *
 * @Date:2022/8/1 20:29
 * @Author:dy
 */
@Component
public class HotelMqExchange {

    @Autowired
    private IHotelService iHotelService;

    /**
     * @Author dy
     * @Description: 监听 hotel 发出的新增和修改队列.
     * * @param null
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(name = MqConstants.HOTEL_EXCHANGE_TOPIC,type = ExchangeTypes.TOPIC),
            value = @Queue(name = MqConstants.HOTEL_INSERT_QUEUE),
            key = MqConstants.HOTEL_INSERT
    ))
    public void listenHotelInsertQueue(Long id){
        iHotelService.insertById(id);
    }

    /**
     * @Author dy
     * @Description: 监听 hotel 发出的删除消息队列.
     * * @param null
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(name = MqConstants.HOTEL_EXCHANGE_TOPIC,type = ExchangeTypes.TOPIC),
            value = @Queue(name = MqConstants.HOTEL_DELETE_QUEUE),
            key = MqConstants.HOTEL_DELETE
    ))
    public void listenHotelDeleteQueue(Long id){
        iHotelService.deleteById(id);
    }









}
